package com.zhong.kotlin.base

import android.content.Context
import android.content.pm.ActivityInfo
import android.os.Bundle
import android.support.v7.app.AppCompatActivity

import com.hjtech.baselib.mvpbase.BasePresenter
import com.hjtech.baselib.mvpbase.BaseView
import com.hjtech.baselib.utils.ActivityManager

/*
 * 项目名:    EasyPark
 * 包名       com.hjtech.easypark.common.base
 * 文件名:    BaseActivity
 * 创建者:    ZJB
 * 创建时间:  2017/6/20 on 14:15
 * 描述:     TODO
 */
abstract class BaseActivity<P : BasePresenter> : AppCompatActivity(), BaseView {
    protected var presenter: P? = null
    var context: Context? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
        context = this
        ActivityManager.appInstance.addActivity(this)
        presenter = initPresenter()
    }

    override fun onResume() {
        /**
         * 设置为横屏
         */
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
        super.onResume()
    }

    override fun onDestroy() {
        ActivityManager.appInstance.removeActivity(this)
        if (presenter != null) {
            presenter!!.detach()
        }
        super.onDestroy()
    }

    abstract fun initPresenter(): P


    override fun showLoadingDialog(msg: String) {

    }

    override fun dimissLoadingDialog() {

    }
}
